﻿namespace Morus
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;

    public static partial class CollectionExtension
    {
        [DebuggerStepThrough]
        public static bool IsNullOrEmpty<T>(this ICollection<T> target)
        {
            return (target == null) || (target.Count == 0);
        }

        [DebuggerStepThrough]
        public static void AddRange<T>(this ICollection<T> target, IEnumerable<T> items)
        {
            Check.Argument.IsNotNull(target, "target");
            Check.Argument.IsNotNull(items, "items");

            if (target.IsReadOnly)
            {
                throw new InvalidOperationException("target collection is readonly.");
            }

            if (target is List<T>)
            {
                (target as List<T>).AddRange(items);
                return;
            }

            foreach (var item in items)
            {
                target.Add(item);
            }
        }
    }
}
